import { Router } from 'express'
import { generateValidatorMiddleware } from '@/middlewares/http-validator'
import { routeHandlerMiddleware } from '@/middlewares/http-request'
import userAuth from '@/middlewares/user-auth'
import { user } from '@/validators'
import { login, logout, info, expiredToken } from '@/controllers/UserController'

const userRouter = Router()

// 用户相关路由，异步的函数都会添加上routeHandlerMiddleware 中间件 用于处理异常

// 用户登录 校验中间件
userRouter.post('/login', generateValidatorMiddleware(user.loginSchema), routeHandlerMiddleware(login))
// 用户信息
userRouter.post('/info', userAuth, info)

// 用户登出
userRouter.post('/logout', userAuth, routeHandlerMiddleware(logout))
// token 过期
userRouter.post('/expiredToken', routeHandlerMiddleware(expiredToken))

export default userRouter
